#ifndef RESPONSEHANDLERTHREADPOOL_H
#define RESPONSEHANDLERTHREADPOOL_H

#include <QMutexLocker>
#include <QList>
#include <QMutex>

#include <QThread>

class ResponseHandlerThread;
class PurgeHandlerThread;

class ResponseHandlerThreadPool
{
public:

    static ResponseHandlerThreadPool* getInstance()
    {
        QMutexLocker locker(&m_mutex);
        if(m_instance == NULL)
        {
            m_instance = new ResponseHandlerThreadPool();
        }
        return m_instance;
    }

    ResponseHandlerThreadPool();

    ~ResponseHandlerThreadPool();

    int addHandlerThread(ResponseHandlerThread* thread);

    int removeHandlerThread(ResponseHandlerThread* thread);

    ResponseHandlerThread *getHandlerThread(unsigned int request_id);

    QList<ResponseHandlerThread*> *getThreadList() const
    {
        return m_runningThreadList;
    }

private:

    void purgeStopThread();

    static ResponseHandlerThreadPool *m_instance;

    static QMutex m_mutex;

   // QMap<unsigned int, ResponseHandlerThreadPool*> *m_runningThreadList;

    QList<ResponseHandlerThread*> *m_runningThreadList;

    PurgeHandlerThread *m_purgeThread;



};

class PurgeHandlerThread : public QThread
{
public:
    PurgeHandlerThread();

    ~PurgeHandlerThread();

    void run();

    void setStop(bool stop)
    {
        m_stop = stop;
    }

private:

    bool m_stop;
};
#endif
